#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+100;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL pre[maxn][202];
LL a[maxn];
vector<LL>ma[300];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n;cin>>n;
    for(LL i=0;i<210;i++) ma[i].clear();
    for(LL i=0;i<n+10;i++){
        for(LL j=0;j<202;j++) pre[i][j]=0;
    }
    for(LL i=1;i<=n;i++) cin>>a[i];
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=200;j++){
            pre[i][j]=pre[i-1][j];
            if(a[i]==j) pre[i][j]++;
        }
    }
    for(LL i=1;i<=n;i++){
        ma[a[i]].push_back(i);
    }
    LL ans=1;
    for(LL i=1;i<=200;i++){

        if(ma[i].size()<=1) continue;
        for(LL j=0,k=ma[i].size()-1;k>=j&&j<ma[i].size();j++,k--){

            LL lsum=pre[ma[i][j]][i];
            LL rsum=pre[n][i]-pre[ma[i][k]-1][i];
            if(ma[i][j]==ma[i][k]) ans=max(ans,2*min(lsum,rsum)-1);
            else ans=max(ans,2*min(lsum,rsum));

            for(LL o=1;o<=200;o++){
                if(ma[i][j]+1>=ma[i][k]){
                    continue;
                }
                ans=max(ans,2*min(lsum,rsum)+pre[ma[i][k]-1][o]-pre[ma[i][j]][o]);
            }
        }
    }
    cout<<ans<<"\n";
  }
return 0;
}
